package com.wenmang.volleynetwork;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Toast;

import com.wenmang.networklib.client.WMCallback;
import com.wenmang.networklib.client.WMNetClient;
import com.wenmang.volleynetwork.bean.Weather;

public class MainActivity extends AppCompatActivity {
    /**
     * https://www.juhe.cn/
     * 可在此网站 获取api接口
     */
    private static String sURL = "http://v.juhe.cn/weather/index?format=2&cityname=%E8%A1%A2%E5%B7%9E&key=您申请的KEY";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    public void doWeather(View v) {
        WMNetClient.sendJSONRequest(null, sURL, Weather.class, new WMCallback<Weather>() {
            @Override
            public void onSuccess(Weather response) {
                Toast.makeText(MainActivity.this, response.getResult().getToday().getCity()
                        + "的天气状况为："
                        + response.getResult().getToday().getTemperature()
                        + response.getResult().getToday().getWeather(), Toast.LENGTH_LONG).show();
            }

            @Override
            public void onFailure(String errorMsg) {
                Toast.makeText(MainActivity.this, errorMsg, Toast.LENGTH_LONG).show();
            }
        });
    }
}
